package com.atguigu03.threadsafe.exer;

/**
 * ClassName: AccountTest
 * Package: com.atguigu03.threadsafe.exer
 * Description:
 *
 * @Author BuTang
 * @Create 2023/5/14 21:47
 * @Version 1.0
 */
public class AccountTest {      // 测试
    public static void main(String[] args) {
        Account a = new Account(0);

        Customer b = new Customer(a);
        //Customer c = new Customer(a);

        Thread d = new Thread(b);
       // Thread e = new Thread(c);
        d.start();
       // e.start();
    }
}

class Account{
    private double balance;

    public Account(double balance) {
        this.balance = balance;
    }

    public Account() {
    }

    public double getBalance() {
        return balance;
    }
}


class Customer implements Runnable{
    private Account account ;
    private double balance = account.getBalance();

    public Customer() {
    }

    public Customer(Account account) {
        this.account = account;
    }

    @Override
    public void run() {
       synchronized (this){
           // balance += 1000;
           for (int i = 0; i < 3; i++) {

               System.out.println(Thread.currentThread().getName() + "存钱成功1000" + "余额为" +balance);
           }

    }

    }
}
